package dataProviders;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

import wrappers.DataType;
import wrappers.Property;



public class PropertyTableModel implements TableModel {
	Set<TableModelListener> tml = new HashSet<TableModelListener>();
	ArrayList<Property> properties = new ArrayList<Property>();
	ArrayList<DataType> types = new ArrayList<DataType>();
	
	public void setProperties(ArrayList<Property> inputProperties, ArrayList<DataType> inputTypes){
		types = inputTypes;
		properties = inputProperties;
	}
	
	@Override
	public void addTableModelListener(TableModelListener arg0) {
		tml.add(arg0);
		
	}

	@Override
	public Class<?> getColumnClass(int arg0) {
		if(arg0 == 0)
			return "".getClass();
		return (new java.lang.Integer(0)).getClass();
	}

	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public String getColumnName(int arg0) {
		if(arg0 == 0)
			return "name";
		return "type";
	}

	@Override
	public int getRowCount() {
		return properties.size();
	}

	@Override
	public Object getValueAt(int arg0, int arg1) {
		if(arg1==0){
			//System.out.println(properties.get(arg0).getName());
			return properties.get(arg0).getName();
		} else {
			//System.out.println(types.get(properties.get(arg0).getType()).getErdType());
			return types.get(properties.get(arg0).getType()).getErdType();
		}
		
	}

	@Override
	public boolean isCellEditable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeTableModelListener(TableModelListener arg0) {
		tml.remove(arg0);		
	}

	@Override
	public void setValueAt(Object arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}

}
